<?php
/**
 * SellerGroupsSeeder.php
 *
 * @copyright  2023 beikeshop.com - All Rights Reserved
 * @link       https://beikeshop.com
 * @author     TL <mengwb@guangda.work>
 * @created    2023-07-26 19:42:42
 * @modified   2023-07-26 19:42:42
 */

namespace Plugin\MultiSeller\Seeders;

use Beike\Models\Setting;
use Beike\Seller\Models\SellerGroup;
use Beike\Seller\Models\SellerGroupDescription;
use Illuminate\Database\Seeder;

class SellerGroupsSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $items = $this->getSellerGroups();
        if ($items) {
            SellerGroup::query()->truncate();
            foreach ($items as $item) {
                SellerGroup::query()->updateOrCreate(['id' => $item['id']], $item);
            }
        }

        $items = $this->getSellerGroupDescriptions();
        if ($items) {
            SellerGroupDescription::query()->truncate();
            foreach ($items as $item) {
                SellerGroupDescription::query()->updateOrCreate(['id' => $item['id']], $item);
            }
        }

        Setting::query()->updateOrCreate(['type' => 'plugin', 'space' => 'multi_seller', 'name' => 'default_seller_group_id'], ['value' => '1', 'json' => 0]);
    }

    public function getSellerGroups(): array
    {
        return [
            [
                'id' => 1,
            ],
        ];
    }

    public function getSellerGroupDescriptions(): array
    {
        return [
            [
                'id'              => 1,
                'seller_group_id' => 1,
                'locale'          => 'zh_cn',
                'name'            => '默认',
                'description'     => '默认商户组',
            ],
            [
                'id'              => 2,
                'seller_group_id' => 1,
                'locale'          => 'en',
                'name'            => 'Default',
                'description'     => 'Default seller group',
            ],
        ];
    }
}
